//BusClearingSandpayModel
//2020-08-10 14:01:43

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type BusClearingSandpayModel struct {
	Model *base.Model
	Field BusClearingSandpayModelField
}

//表字段
type BusClearingSandpayModelField struct {
	T_table             string `default:"bus_clearing_sandpay"`
	F_id                string `default:"id"`
	F_bus_id            string `default:"bus_id"`
	F_order_sn          string `default:"order_sn"`
	F_amount            string `default:"amount"`
	F_depository_amount string `default:"depository_amount"`
	F_usable_amount     string `default:"usable_amount"`
	F_real_amount       string `default:"real_amount"`
	F_fee               string `default:"fee"`
	F_status            string `default:"status"`
	F_error_msg         string `default:"error_msg"`
	F_query_count       string `default:"query_count"`
	F_agent_time        string `default:"agent_time"`
	F_card_name         string `default:"card_name"`
	F_card_no           string `default:"card_no"`
	F_card_bank_name    string `default:"card_bank_name"`
	F_card_bank_no      string `default:"card_bank_no"`
	F_create_time       string `default:"create_time"`
}

//初始化
func (b *BusClearingSandpayModel) Init(ormer ...orm.Ormer) *BusClearingSandpayModel {
	functions.ReflectModel(&b.Field)
	b.Model = base.NewModel(b.Field.T_table, ormer...)
	return b
}

//新增数据
func (b *BusClearingSandpayModel) Insert(data map[string]interface{}) int {
	result, _ := b.Model.Data(data).Insert()
	return result
}

// 根据busId和状态查询记录
func (b *BusClearingSandpayModel) FindByBusIdAndStatus(busId, status interface{}) map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_bus_id: busId,
		b.Field.F_status: status,
	}).Find()
}

// 根据Id和状态更新记录
func (b *BusClearingSandpayModel) UpdateByIdAndStatus(id, status interface{}, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_id:     id,
		b.Field.F_status: status,
	}).Data(data).Update()
}

// 根据Id和状态更新记录
func (b *BusClearingSandpayModel) UpdateAgent(id, status, amount interface{}, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_id:     id,
		b.Field.F_status: status,
		b.Field.F_amount: amount,
	}).Data(data).Update()
}

// 根据Id和状态查询记录
func (b *BusClearingSandpayModel) GetListsByStatus(status, id, count int) []map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_status: status,
		b.Field.F_id:     []interface{}{"gt", id},
	}).Limit(0, count).OrderBy(b.Field.F_id).Select()
}

// 无实时返回的数据后续查询处理
func (b *BusClearingSandpayModel) GetFundIngList(status, id, count int) []map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_status:     status,
		b.Field.F_id:         []interface{}{"gt", id},
		b.Field.F_agent_time: []interface{}{"gt", 0},
	}).Limit(0, count).OrderBy(b.Field.F_id).Select()
}
